using NHibernate;
using NHibernate.Cfg;

namespace EventApp.Lib.Helper
{
    public class SessionBuilder : ISessionBuilder
    {
        private ISessionFactory _sessionFactory = null;
        private ISession _session;
        public SessionBuilder()
        {
            Configuration config = new Configuration();
            config.AddAssembly("EventApp.Lib");
            _sessionFactory = config.Configure().BuildSessionFactory();
        }

        public ISession GetSession()
        {
            if(_session == null||!_session.IsOpen)
            {
                _session = _sessionFactory.OpenSession();
            }

            return _session;
        }
    }
}